<? $first_poll_id = 0;?>
<div id="heading">
    <div id="headinginner">
        <h1><span>Vijesti</span></h1>
        <p class="clear"></p>
    </div>                          
</div>                              
<div id="stage-inner">
    <?
        if(isset($_POST['info'])){
        ?>
        <div class="info" style="min-height: 25px;">
            <p><?=$_POST['message']?></p>
            <a class="button dismiss javascript" href="javascript:void(0)" style="display: inline;">Zatvori</a>
            <p class="clear"></p>
        </div>
        <p class="clear"> </p>
        <script>
            $('.dismiss').bind('click', function(){
                $('.info').fadeOut('slow');
            })
        </script>
        <?    
        }
    ?>
    <div class="box nopadding" style="margin-top: 15px; border: 1px solid #D2D0D0; background: #FFFFFF;">
        <div class="qoptions qoptionssmlpadding"> 
            <div class="right">
                <a class="button new-item" href="<?=base_url()?>vesti/uredi_vesti">Kreirajte novu vijest</a>
            </div>
            <p class="clear"></p>
        </div>
        <table cellspacing="0" cellpadding="0" class="folder-table">
            <tbody>
                <tr>
                    <td style="border-right: 1px solid #CCCBCA;">
                        <div style="height: 520px;">
                            <div id="ankete" class="" role="tablist">
                                <div class="ankete-content-list" style="height: 497px; overflow: auto;" role="tabpanel">
                                    <? 
                                        if(count($vesti)==0){?>
                                        <div class="no-votes">Još uvek niste kreirali nijednu vijest. Kada to uradite, moćićete da ih vidite ovdje!</div>
                                        <?}else{?>
                                        <ul> 
                                            <? $selected=TRUE; foreach($vesti as $vest){ ?>
                                                <li id="<?=$vest->id;?>" <? if($selected){ echo 'class="selected"'; $selected=false; $first_news_id = $vest->id; } ?>>
                                                    <a href="javascript:void(0)" class="edit">
                                                        <span class="item-status <? if($vest->status==2){echo 'closed';}else{echo 'open';}?>"></span>
                                                        <?=$vest->title; ?>
                                                    </a>
                                                    <p class="clear"></p>
                                                </li> 
                                                <? } ?>
                                        </ul>
                                        <? } ?>     
                                </div>
                            </div>
                        </div>
                    </td>
                    <td id="minireport">

                    </td>
                </tr> 
            </tbody>
        </table>
    </div>  
</div>
<div id="poll-status-modal" style="display: none;">
    <div id="poll-status-holder" class="dialog">
        <div class="body">
            <div class="title" id="status-title"></div>
            <div class="text">
                <p id="status-text"></p>                              
            </div>
        </div>

        <div class="controls">
            <div class="right">
                <a href="javascript:void(0)" class="plain custom-styles-done">Otkaži</a>
                <a class="button confirm-poll-status" href="javascript:void(0)" id="">Potvrdi</a>
                <p class="clear"></p>
            </div>
            <p class="clear"></p>
        </div> 
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        function prikazi_vest(id){
            $.ajax({
                type: 'POST',
                url: base_url+'vesti/uredi_vesti/prikazi_vest',
                data:{id:id},
                dataType: 'json',
                success: function(data){
                    $('#minireport').html(data.html);
                    $('#minireport').show();            
                },
                error:function(data){alert("Error: " + data);}
            });
            return false;
        }
        $('.ankete-content-list li').live('click',function(){
            $('#minireport').hide();
            var id = this.id;
            prikazi_vest(id);
            $('.ankete-content-list li').each(function(index, value){
                $(value).removeClass('selected');
                if(id==value.id){
                    $(value).addClass('selected');
                }
            })            
        })
        var first_id = '<?=$first_news_id;?>';
        if(first_id!=0){
            prikazi_vest(first_id);   
        };
    });
</script>
